﻿-- =============================================
-- Author:		Jon Stocksdale
-- Create date: May 12, 2016
-- Description:	Returns the ShortName of the TimeDiv which a particular date is in
-- =============================================
CREATE FUNCTION [dbo].[GetExactTimeDiv]
(
	-- Add the parameters for the function here
	@StartDate datetime,
	@EndDate datetime,
	@InstitutionID int = 0
)
RETURNS nvarchar(10)
AS
BEGIN
	-- Declare the return variable here
	DECLARE @WhichTimeDiv nvarchar(10)
	SELECT @WhichTimeDiv=ShortName FROM dbo.TimeDivisions
		 WHERE StartDate = @StartDate AND EndDate = @EndDate
	
	RETURN @WhichTimeDiv

END